'use strict'
Object.defineProperty(exports, '__esModule', { value: true })
var relation_1 = require('../../miniprogram_npm/@vant/weapp/common/relation')
var component_1 = require('../../miniprogram_npm/@vant/weapp/common/component')
component_1.VantComponent({
  field: true,
  relation: relation_1.useParent('dropdown-menu', function () {
    this.updateDataFromParent()
  }),
  props: {
    value: {
      type: null,
      observer: 'rerender',
    },
    title: {
      type: String,
      observer: 'rerender',
    },
    disabled: Boolean,
    titleClass: {
      type: String,
      observer: 'rerender',
    },
    options: {
      type: Array,
      value: [],
      observer: 'rerender',
    },
    popupStyle: String,
    // 魔改
    isCheck: {
      type: Boolean,
      value: true,
      observer: 'rerender',
    },
  },
  data: {
    transition: true,
    showPopup: false,
    showWrapper: false,
    displayTitle: '',
    selectList: [],
  },
  methods: {
    rerender: function () {
      var _this = this
      wx.nextTick(function () {
        var _a; 
        // void 0和undefined是等价的
        (_a = _this.parent) === null || _a === void 0 ? void 0 : _a.updateItemListData()
      })
    },
    updateDataFromParent: function () {
      if (this.parent) {
        var _a = this.parent.data,
          overlay = _a.overlay,
          duration = _a.duration,
          activeColor = _a.activeColor,
          closeOnClickOverlay = _a.closeOnClickOverlay,
          direction = _a.direction
        this.setData({
          overlay: overlay,
          duration: duration,
          activeColor: activeColor,
          closeOnClickOverlay: closeOnClickOverlay,
          direction: direction,
        })
      }
    },
    onOpen: function () {
      this.$emit('open')
    },
    onOpened: function () {
      this.$emit('opened')
    },
    onClose: function () {
      this.$emit('close')
    },
    onClosed: function () {
      this.$emit('closed')
      this.setData({ showWrapper: false })
    },
    // 改动cell，实现多选单选，第一次点击高亮第二次点击失活
    onOptionTap: function (event) {
      var option = event.currentTarget.dataset.option
      var value = option.value
      let { isCheck, selectList } = this.data
      if (isCheck) {
        let index = selectList.indexOf(value)
        if (index > -1) {
          selectList.splice(index, 1)
        } else {
          selectList.push(value)
        }
        this.setData({
          selectList: selectList,
        })
        this.$emit('change', value)
      } else {
        let index = selectList.indexOf(value)
        if (index > -1) {
          selectList.splice(index, 1)
        } else {
          selectList[0] = value
        }
        this.setData({
          showPopup: false,
          selectList: selectList,
        })
        this.$emit('change', value)
      }
      this.$emit('close')
      this.rerender()
    },
    // 懂得都懂
    toggle: function (show, options) {
      var _this = this
      var _a
      if (options === void 0) {
        options = {}
      }
      var showPopup = this.data.showPopup
      if (typeof show !== 'boolean') {
        show = !showPopup
      }
      if (show === showPopup) {
        return
      }
      this.setData({
        transition: !options.immediate,
        showPopup: show,
      })
      if (show) {
        ; (_a = this.parent) === null || _a === void 0
          ? void 0
          : _a.getChildWrapperStyle().then(function (wrapperStyle) {
            _this.setData({ wrapperStyle: wrapperStyle, showWrapper: true })
            _this.rerender()
          })
      } else {
        this.rerender()
      }
    },
  },
})
